<!DOCTYPE html>
<!-- manifest="/header.appcache" -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>采购定制</title>
</head>
<script src="../../js/edition.js"></script>
<link rel="stylesheet" href="../../css/base.css">
<link rel="stylesheet" href="../../css/lq.datetimepick.css">
<script>
document.write("<l"+"ink rel='stylesheet' href='../../css/style.css?version="+edition+"'>")
</script>
<script>
document.write("<l"+"ink rel='stylesheet' href='../../css/index.css?version="+edition+"'>")
</script>
<link rel="stylesheet" href="../../css/popover.css">
<script src="../../js/jquery.js"></script>
<script src="../../js/popover.js"></script>
<script src="../../js/template.js"></script>
<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/url.js?version="+edition+"'></scr"+"ipt>"); 
</script>

<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/index.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/header.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<script src="../../js/index_foot.js"></script>
<script src="../../js/jquery.cookie.js"></script>
<script> 
        document.write("<s"+"cript type='text/javascript' src='../../js/p_login.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<script src="../../js/cookie.js"></script>
<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-4.4.4.min.js"></script>
<script> 
    document.write("<s"+"cript type='text/javascript' src='../../js/no_login.js?version="+edition+"'></scr"+"ipt>"); 
</script>
<body style="background:#fff">
    <header class="mod_head">
        <script>
            $(function(){
                var src=$('.mod_logo img').attr('src')
                $('.mod_logo img').attr('src','../'+src)
            })   
        </script> 
    </header>
    <div class="purchase_banner">
        <img src="../../img/service_banner.png" alt="" srcset="">
    </div>
    <div class="purchase_bg">
        <div class="purchase_left">
            <dl>
               <dt>
                    <span class="fl">企业定制流程</span>  
                    <span class="fr">
                        <a href="tencent://message/?uin=2151577512&Site=http://vps.shuidazhe.com&Menu=yes">
                                联系客服   
                        </a> 
                    </span>  
               </dt>
               <dd>
                    <em><img src="../../img/service/ic_1.png" alt=""></em>   提交定制单
               </dd> 
               <dd>|</dd>
               <dd>
                    <em><img src="../../img/service/ic_2.png" alt=""></em>   沟通定制细节
               </dd>
               <dd>|</dd> 
               <dd>
                    <em><img src="../../img/service/ic_3.png" alt=""></em>   定制单付款
               </dd>
               <dd>|</dd> 
               <dd>
                    <em><img src="../../img/service/ic_4.png" alt=""></em>   等待收货/服务
               </dd>
               <dd>|</dd> 
               <dd>
                    <em><img src="../../img/service/ic_5.png" alt=""></em>   定制服务完成
               </dd> 
            </dl>
            <ul>
                <li>请注意：</li>
                <li>
                        1.提交定制单后,我们会在第一时间
                        与您取得联系,与您了解需求后会给
                        出一份方案。
                </li>
                <li>
                        2.沟通后,双方确定定制方案后,你再
                        付款。
                </li>
                <li>
                        3.完成付款后, 平台将会在约定
                        好的时间内将服务/商品送到您身边。
                </li>
            </ul>
        </div>
        <div class="purchase_right">
           <dl>
             <dt>
                <span class="fl">定制需求单</span>  
            </dt> 
            <dd>
                <span>
                        定制标题
                </span>
                <em>
                    <input type="text" name="" class="text title" placeholder="请输入定制标题">
                </em>
            </dd> 
            <dd>
                <span>定制分类</span>
                <em class="tab">
                    <a href="javascript:;" class="active" data-type='1'>商品定制</a>
                    <a href="javascript:;" data-type='2'>出行定制</a>
                </em>
            </dd>
            <dd style="margin-bottom:8px">
                <span>
                    定制明细
                </span>
                <div class="d_right">
                    
                </div>
                <div class="pu_add">
                        
                </div>
            </dd>
            <dd>
                <span>预算总额</span>
                <em class="mon3" data-b="0.00" style="line-height:34px; font-size:18px; color:#f10215;font-weight:600">
                    ￥0.00
                </em>
            </dd>
            <dd>
                <span>
                        联系人
                </span>
                <em>
                    <input type="text" class="text  linkman" name="" id="">
                </em>
            </dd>
            <dd>
                <span>
                        联系电话
                </span>
                <em>
                    <input type="text" class="text linkPhone">
                </em>
            </dd>
            <dd>
                <span>
                        服务时间
                </span>
                <em>
                    <input readonly type="text" class="text serveTime" name="datepicker" value="2017-11-05">
                </em>
            </dd>
            <dd>
                <span>
                        补充说明
                </span>
                <em>
                    <input type="text" class="text explain1">
                </em>
            </dd>
            <dd style="margin-bottom:16px">
                <em>
                    <a id="commit" style="margin-left:80px" href="javascript:;" class="active">提交</a>    
                </em>                
            </dd>
        </dl> 
        </div>
    </div>
    <footer class="mod_foot"></footer>
    <script> 
       document.write("<s"+"cript type='text/javascript' src='../../js/nav_hover.js?version="+edition+"'></scr"+"ipt>"); 
    </script> 
    <script src="../../js/selectUi.js"></script>
    <script src="../../js/lq.datetimepick.js"></script> 
    <script>
    $(function(){
        /**
        * 生成文件名
        * @returns
        */
        function timestamp(){  
            var time = new Date();  
            var y = time.getFullYear();  
            var m = time.getMonth()+1;  
            var d = time.getDate();  
            var h = time.getHours();  
            var mm = time.getMinutes();  
            var s = time.getSeconds();                      
            return ""+y+add0(m)+add0(d)+add0(h)+add0(mm)+add0(s);  
        }
        function timestamp2(){  
            var time = new Date();  
            var y = time.getFullYear();  
            var m = time.getMonth()+1;  
            var d = time.getDate();  
            var h = time.getHours();  
            var mm = time.getMinutes();  
            var s = time.getSeconds();                      
            return ""+y+'/'+add0(m)+'/'+add0(d);  
        }  
        function add0(m){  
        return m<10?'0'+m : m;  
        }
        var client = new OSS.Wrapper({
            region : 'oss-cn-hangzhou',
            accessKeyId : 'qftEuqKzjdvGJ4tH',
            accessKeySecret : '8k7NM6kiyGCdpK5Yf3DCUhkAV1LEql',
            bucket : 'gouba001'
        });
        // 服务定制
        var service=''    
        var service1=''
        var add_goods=''  
        var add_goods1=''                    
        service1+='<div class="purchase_tit">'
        service1+='<span class="s1">'
        service1+='<i>*</i>服务名称'
        service1+='</span>'
        service1+='<span class="s2">'
        service1+='<i>*</i>人数'
        service1+='</span>'
        service1+='<span class="s3">'
        service1+='<i>*</i>预算单价'
        service1+='</span>'
        service1+='<span class="s4" style="width:328px">说明'
        service1+='</span>'
        service1+='<span class="s6">操作</span>'
        service1+='</div>'
        service1+='<ul>'
        service+='<li data-m="0">'
        service+='<span class="s1">'
        service+='<input type="text" class="name errors">'
        service+='</span>'
        service+='<span class="s2">'
        service+='<input type="text" class="mon2 num" value="1">'
        service+='</span>'
        service+='<span class="s3">'
        service+='<input class="mon price errors" type="text" value="0.00">'
        service+='</span>'
        service+='<span class="s4" style="width:328px">'
        service+='<textarea style="width:88%;min-width:88%;max-width:88%" name="" id="" class="explain"></textarea> '
        service+='</span>'
        service+='<span class="s6 dele">'
        service+='删除'
        service+='</span>'
        service+='</li>'
        service1+='</ul>'
        //商品定制
        add_goods1+='<div class="purchase_tit">'
        add_goods1+='<span class="s1">'
        add_goods1+='<i>*</i>商品名称'
        add_goods1+='</span>'
        add_goods1+='<span class="s2">'
        add_goods1+='<i>*</i>商品数量'
        add_goods1+='</span>'
        add_goods1+='<span class="s3">'
        add_goods1+='<i>*</i>预算单价'
        add_goods1+='</span>'
        add_goods1+='<span class="s4">'
        add_goods1+='说明'
        add_goods1+='</span>'
        add_goods1+='<span class="s5">'
        add_goods1+='图片'
        add_goods1+='</span>'
        add_goods1+='<span class="s6">'
        add_goods1+='操作'
        add_goods1+='</span>'
        add_goods1+='</div>'
        add_goods1+='<ul>'
        add_goods+='<li data-m="0">'
        add_goods+='<span class="s1">'
        add_goods+='<input type="text" class="name errors">'
        add_goods+='</span>'
        add_goods+='<span class="s2">'
        add_goods+='<input type="text"  class="mon2 num" value="1">'
        add_goods+='</span>'
        add_goods+='<span class="s3">'
        add_goods+='<input class="mon  price errors" type="text" value="0.00">'
        add_goods+='</span>'
        add_goods+='<span class="s4">'
        add_goods+='<textarea name="" id="" class="explain"></textarea> '
        add_goods+='</span>'
        add_goods+='<span class="s5">'
        add_goods+='<em><img class="img" src=""> +<input type="file" name="" id="" class="picture"><input class="picture2" type="hidden" ></em>'
        add_goods+='<div id="click"></div></span>'
        add_goods+='<span class="s6 dele">'
        add_goods+='删除'
        add_goods+=' </span>'
        add_goods+=' </li>'
        add_goods1+='</ul>'

        var type=''
        var u=window.location.href
        var u2=u.split('=')[1]
        if(u2=='2'){
            $('.tab a').removeClass('active')
            $('.tab a').eq(1).addClass('active')
        }
        type=$('.tab a.active').attr('data-type')
        $(".serveTime").on("click",function(e){
            e.stopPropagation();
            $(this).lqdatetimepicker({
                css : 'datetime-day',
                dateType : 'D',
                selectback : function(){}
            });
        });
        //删除服务
        function dele(){
            $('.d_right ul li').each(function(index,t){
               $(t).find('.dele').click(function(){
                if($('.d_right ul li').length<='1'){
                    tc('不能删除')
                    $('.purchase_right li').last().css('border-bottom','0')
                    $('.price').focus()
                    // $('.mon3').attr('data-b','0.00')
                    // $('.mon2').val('1')
                    // $('.mon').val('0.00')
                    // $('.mon3').text('￥0.00')
                    // return false
                }
                else{
                    // $('.mon3').text('￥'+(y-parseFloat($(t).attr('data-m'))).toFixed(2))
                    // $('.mon3').attr('data-b',u)
                    $(t).remove()
                    $('.purchase_right li').last().css('border-bottom','0')
                    var y=0
                    // var u=y-parseFloat($(t).attr('data-m'))
                    setTimeout(function(){
                        $('.purchase_right li').each(function(index,t){
                           y+=parseFloat($(t).attr('data-m'))
                        })
                        $('.mon3').text('￥'+y.toFixed(2))
                        $('.mon3').attr('data-b',y)
                    },100)
                }   
               }) 
            })
        }
        // 判断显示哪种服务
        function add(){
            if(type=='1'){
                $('.d_right').html('').append(add_goods1);
                $('.d_right ul').html('').append(add_goods);
                $('.pu_add').html('').append('<a href="javascript:;" class="add_goods">增加商品</a>（温馨提示:商品图片文件大小须≤5MB，文件格式支持jpg、png、gif、bmp、jpeg。）');
                // 点击添加增加
                function add_1(){
                    $('.add_goods').click(function(){
                        // $('.none').remove()
                        $('.d_right ul').append(add_goods);
                        $('.purchase_right li').css({
                            'border-bottom':'#e0e0e0 solid 1px',
                        }).last().css('border-bottom','0');
                        mon();
                        dele();
                        fir()
                        nu()
                        return false;
                        })
                }add_1()
                dele();
                mon()
                nu()
            }
            else{
                $('.d_right').html('').append(service1)
                $('.d_right ul').html('').append(service)
                $('.pu_add').html('').append('<a href="javascript:;" class="add_goods">增加服务</a>')
                function add_1(){
                    $('.add_goods').click(function(){
                        // $('.none').remove()
                        $('.d_right ul').append(service)
                        $('.purchase_right li').css({
                            'border-bottom':'#e0e0e0 solid 1px',
                        }).last().css('border-bottom','0');
                        mon();
                        dele();
                        fir()
                        nu()
                        return false
                    })
                }add_1()
                dele();
                mon()
                nu()
            }
        }add()
        //预算总额
        function mon(){
                var m=''
                var m2=''
                var m3=0
                $('.purchase_right li').each(function(index,t){
                    $(t).find('.mon, .mon2').change(function(){
                        var a1=''
                        var b1=''
                        var z1=''
                        var z2=''
                        if($(t).find('.mon').val()==''){
                            $(t).find('.mon').val('0.00').addClass('errors')
                        }
                        if($(t).find('.mon2').val()==''){
                            $(t).find('.mon2').val('1')
                        }
                        m+=$(t).find('.mon').val()+","
                        m2+=$(t).find('.mon2').val()+","
                        a1=m.split(',');
                        b1=m2.split(',');
                        for(var f=0; f< (a1.length)-1; f++){
                            z1=parseFloat(a1[f])
                        }
                        for(var g=0; g< (b1.length)-1; g++){
                            z2=parseFloat(b1[g])
                        }
                        $(t).attr('data-m',parseFloat(z1)*parseFloat(z2))                       
                    })
                })
                $('.mon, .mon2').blur(function(){
                    var n=0
                    $('.purchase_right li').each(function(){
                        n+=parseFloat($(this).attr('data-m'))
                        $('.mon3').text('￥'+n.toFixed(2))
                        $('.mon3').attr('data-b',n)
                        if($(this).find('.mon').val()>'0.01'){
                            $(this).find('.mon').removeClass('errors')
                        }
                    })
                })
                $('.name').blur(function(){
                    $('.purchase_right li').each(function(){
                        if($(this).find('.name').val()!=''){
                            $(this).find('.name').removeClass('errors')
                        }
                        else{
                            $(this).find('.name').addClass('errors')
                        }
                    })
                })
        }
        function fir(){
            $(".picture").on("change", function(e){
                $(".picture").removeClass('yes')
                $(this).addClass('yes')
                var files = this.files;
                var img = new Image();
                // console.log(img)
                var reader = new FileReader();
                var ty=$(this).val()
                if($('.yes').val()==''){
                    $('.yes').parents('em').find('img').attr('src','')
                    $('.yes').parents('em').find('picture2').val('')
                }
                reader.readAsDataURL(files[0]);
                if(!/\.(gif|jpg|jpeg|png|bmp|GIF|JPG|PNG|BMP)$/.test(ty)){
                  tc("上传类型错误")
                  $(this).val('')
                  $('.yes').parents('em').find('picture2').val('')
                  return false;
                }else{
                    reader.onload = function(e){
                    var mb = (e.total/1024)/1024;
                    // console.log(mb)
                    if(mb>=5){
                        tc('图片不能大于5M');
                        $('.yes').val('')
                        $('.yes').removeClass('yes')
                        $('.yes').parents('em').find('picture2').val('')
                        return false;
                    }else{
                        img.src = this.result;
                        $('.yes').parents('em').find('img').attr('src',img.src)
                    }
                }
                }
                    var suffix = ty.substr(ty.indexOf("."));
                    var f =this.files[0]; 
                    var obj2=timestamp2()//路径
                    var obj=timestamp();  //这里是生成文件名
                    var storeAs = 'shop/customization'+"/"+obj2+'/'+obj+suffix;  //命名空间
                    // console.log(storeAs)
                    $('.yes').parents('em').find('.picture2').val(storeAs)
                    // var form = new FormData(); 
                    // form.append("file", f);
                    // $.ajax({
                    //     url:new_url+'shop/public/uploadFile',
                    //     data:form,
                    //     type:'post',
                    //     dataType:'json',
                    //     success:function(e){
                    //         console.log(e)
                    //     }
                    // })
                    // client.multipartUpload(storeAs, f).then(function (result){
                    //        $('.yes').parents('em').find('.picture2').val(result.name)
                    // }).catch(function (err){

                    // });   
            });
        } fir()
        
        //qiehuan
        $('.tab a').click(function(){
            $(this).addClass('active').siblings().removeClass('active')
            type=$('.tab a.active').attr('data-type')
            $('.mon3').text('￥0.00').attr('data-b','0.00')
            add()
        })    
        var d = new Date();
        var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
        $('.serveTime').val(str)
        function nu(){
            $(".num").keyup(function(){
            if($(this).val()<'1'){
                $(this).val('')
            }
            $(this).val($(this).val().replace(/[^0-9]/g,''));  
            }).bind("paste",function(){  //CTR+V事件处理  
                $(this).val($(this).val().replace(/[^0-9]/g,''));   
            }).css("ime-mode", "disabled"); //CSS设置输入法不可用  

            $('.price').keyup(function(){ 
                $(this).val($(this).val().replace(/[^\d\.]/g,''));
                var t=$(this).val()
                var th=t.substr(0,1)
                var th2 = t.substr(1,1);
                if(th=='.'){
                    $(this).val('')
                }
                if(th2.length >= 1 && th==0 && th2 != '.'){  
                    $(this).val(th2)
                }  
                
            }).bind("paste",function(){  //CTR+V事件处理  
                $(this).val($(this).val().replace(/[^\d\.]/g,''));   
            }).css("ime-mode", "disabled"); //CSS设置输入法不可用  
            $('.price').blur(function(){
                if($(this).val()==''){
                    $(this).val('0.00')
                }
            })
            $('.num').blur(function(){
                if($(this).val()<'1'){
                    $(this).val('1')
                }
            })
        }
        //提交
            if($.cookie('user')!=''&&$.cookie('user')!=null){
                strs=$.cookie('user').split(","); 
                var token=''; 
                for(var i in strs){ 
                    token=strs[6]  
                }
            $('#commit').click(function(){
            var d = new Date();
            var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
            if($('.title').val()==''){
            tc('请输入标题')
            return false
            }
            
            if($('.name').hasClass('errors')){
                tc('请输入名称')
                return false
            }
            if($('.price').hasClass('errors')){
                tc('请输入单价')
                return false
            }
                        
            if($('.linkman').val()==''){
                tc('请输入联系人')
                return false
            }
            var phone = $('.linkPhone').val();
            if(phone==''){
                tc('请输入手机号')
                return false;
            }
            if(!(/^1(3|4|5|7|8)\d{9}$/.test(phone))){
                tc('请输入正确的手机号')
                return false;    
            }
            if($('.serveTime').val()<str){
                tc('请选择正确日期')
                return false
            }  
                var title=$('.title').val();
                var customType=type;
                var budgetAmount=$('.mon3').attr('data-b');
                var linkMan=$('.linkman').val();
                var linkPhone=$('.linkPhone').val();
                var serveTime=$('.serveTime').val()
                var explain1=$('.explain1').val()
                var name=''
                var num=''
                var expectUnitPrice=''
                var explain=''
                var picture=''
                var customDetailList=''
                $('.purchase_right li').each(function(){
                        name=$(this).find('.name').val()
                        num=$(this).find('.num').val()
                        expectUnitPrice=$(this).find('.price').val()
                        explain=$(this).find('.explain').val()
                        picture=$(this).find('.picture2').val()
                        customDetailList+='"name":'+'"'+name+'"'+','+'"num":'+'"'+num+'"'+','+'"expectUnitPrice":'+'"'+expectUnitPrice+'"'+','+'"explain":'+'"'+explain+'"'+','+'"picture":'+'"'+picture+'"'+'|'
                })
                
                if (customDetailList.length>0){
                    customDetailList = customDetailList.substr(0, customDetailList.length - 1);
                }
                var customDetailList2=customDetailList.split('|')
                var customDetailList3=''
                for (var g=0; g<customDetailList2.length; g++){
                    customDetailList3+='{'+customDetailList2[g]+'}'+','
                }
                if (customDetailList3.length>0){
                    customDetailList3 = customDetailList3.substr(0, customDetailList3.length - 1);
                }
                var customDetailList4='['+customDetailList3+']'
                $('.purchase_right li .picture').each(function(){
                    var fp=1024*1024
                    var f =this.files[0]; 
                    // console.log(f)
                    var f2=$(this).parents('em').find('.picture2').val()
                    // $('.yes').parents('em').find('.picture2').val(storeAs)
                    
                    client.multipartUpload(f2, f).then(function (result){
                            // console.log('成功')
                            // console.log(result)
                            // $('.yes').parents('em').find('.picture2').val(result.name)
                    }).catch(function (err){
                            // console.log('失败')
                            // console.log(err)
                    });   
                })
                $.ajax({
                    type:'post',
                    url:new_url+'shop/customization/addEnterpriseCustom',
                    data:{title:title,customType:customType,budgetAmount:budgetAmount,linkMan:linkMan,linkPhone:linkPhone,serveTime:serveTime,explain:explain1,token:token,customDetailList:customDetailList4},
                    dataType:'json',
                    success:function(e){
                        if(e.code=='0'){
                            tc(e.message)
                            setTimeout(function(){
                                window.location.href="purchase_ok.html" 
                            },300)
                        }
                        else{
                            tc(e.message)
                        }
                    }
                }) 
            })
            }
            else{
                window.location.href='/src/login/login.html?tpye=2'      
            }
    })
    </script>  

</body>
</html>